package com.zr.inquiry.controller;

import com.zr.inquiry.pojo.InquiryAddVo;
import com.zr.inquiry.pojo.InquirySelectVo;
import com.zr.inquiry.pojo.InquiryUpdateVo;
import com.zr.inquiry.service.InquiryService;
import com.zr.util.ResultVo;
import com.zr.util.ResultVoBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created by 陈紫陌 on 2019-10-09.
 * 询价单controller层
 */
@RestController
public class InquiryController {

    @Autowired
    private InquiryService inquiryService;


    /**
     * 询价单新增方法
     * @return
     */
    @PostMapping("/legalPlant/add")//不确定，随缘吧
    public ResultVo addInquiry(@RequestBody @Valid InquiryAddVo inquiryAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultVoBuilder.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return inquiryService.addInquiry(inquiryAddVo);

    }
    /**
     * 询价单查看方法（接口）
     * @return
     */
    @PostMapping("/legalPlant/query")//假的，没调
    public ResultVo see(Integer id){
        return inquiryService.queryById(id);

    }
    /**
     * 询价单修改方法
     * @return
     */
    @PostMapping("/legalPlant/update")//也是假的，没调
    public ResultVo updateInquiry(@RequestBody @Valid InquiryUpdateVo inquiryUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultVoBuilder.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return inquiryService.updateInquiry(inquiryUpdateVo);

    }
    /**
     * 询价单分页查询方法
     * @return
     */
    @PostMapping("/legalPlant/queryPage")//
    public ResultVo queryPage(@RequestBody @Valid InquirySelectVo inquirySelectVo, BindingResult bindingResult){

        return inquiryService.queryPage(inquirySelectVo);

    }
}
